package com.ruoyi.project.modules.interfaceObject.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.modules.interfaceObject.domain.InterfaceObject;
import com.ruoyi.project.modules.interfaceObject.service.IInterfaceObjectService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 接口对象关系Controller
 * 
 * @author smallrain
 * @date 2021-11-04
 */
@Controller
@RequestMapping("/interfaceObject/interfaceObject")
public class InterfaceObjectController extends BaseController
{
    private String prefix = "interfaceObject/interfaceObject";

    @Autowired
    private IInterfaceObjectService interfaceObjectService;

    @RequiresPermissions("interfaceObject:interfaceObject:view")
    @GetMapping()
    public String interfaceObject()
    {
        return prefix + "/interfaceObject";
    }

    /**
     * 查询接口对象关系列表
     */
    @RequiresPermissions("interfaceObject:interfaceObject:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(InterfaceObject interfaceObject)
    {
        startPage();
        List<InterfaceObject> list = interfaceObjectService.selectInterfaceObjectList(interfaceObject);
        return getDataTable(list);
    }

    /**
     * 导出接口对象关系列表
     */
    @RequiresPermissions("interfaceObject:interfaceObject:export")
    @Log(title = "接口对象关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(InterfaceObject interfaceObject)
    {
        List<InterfaceObject> list = interfaceObjectService.selectInterfaceObjectList(interfaceObject);
        ExcelUtil<InterfaceObject> util = new ExcelUtil<InterfaceObject>(InterfaceObject.class);
        return util.exportExcel(list, "接口对象关系数据");
    }

    /**
     * 新增接口对象关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存接口对象关系
     */
    @RequiresPermissions("interfaceObject:interfaceObject:add")
    @Log(title = "接口对象关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(InterfaceObject interfaceObject)
    {
        return toAjax(interfaceObjectService.insertInterfaceObject(interfaceObject));
    }

    /**
     * 修改接口对象关系
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        InterfaceObject interfaceObject = interfaceObjectService.selectInterfaceObjectById(id);
        mmap.put("interfaceObject", interfaceObject);
        return prefix + "/edit";
    }

    /**
     * 修改保存接口对象关系
     */
    @RequiresPermissions("interfaceObject:interfaceObject:edit")
    @Log(title = "接口对象关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(InterfaceObject interfaceObject)
    {
        return toAjax(interfaceObjectService.updateInterfaceObject(interfaceObject));
    }

    /**
     * 删除接口对象关系
     */
    @RequiresPermissions("interfaceObject:interfaceObject:remove")
    @Log(title = "接口对象关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(interfaceObjectService.deleteInterfaceObjectByIds(ids));
    }
}
